package vinnichenko.lab3.database;

import vinnichenko.lab3.exception.*;

import java.util.*;

/**Represents employee table.
 * @author Igor Vinnichenko
 * @version 1.0
 */
public class EmployeeDB{
    /**Pointer to DAO*/
    private EmployeesDAO db = null;

    /**Constructor.*/
    public EmployeeDB(){
    }

    /**Set data access object.
     * @param db DAO.
     */
    public void setDatabase(EmployeesDAO db){
        this.db = db;
    }

    /**Get employee information from database.
     * @param id of employee.
     * @return object containing information.
     * @throws EmployeeNotFoundException
     */
    public EmployeeInfo getEmployee(String id)
        throws EmployeeNotFoundException, DatabaseConnectException{

        return db.getEmployee(id);
    }

    /**Get list with information about all employees from database.
     * @return list containing information.
     * @throws EmployeesNotFoundException
     */
    public List<EmployeeInfo> getHierarchyList()
        throws EmployeesNotFoundException, DatabaseConnectException{

        return db.getHierarchyList();
    }

    /**Delete employee method.
     * @param id of employee.
     * @return true if success.
     * @throws EmployeeNotFoundException
     */
    public boolean deleteEmployee(String id)
        throws EmployeeNotFoundException, DatabaseConnectException{

        return db.deleteEmployee(id);
    }

    /**Add new record to database.
     * @param ename name of new employee.
     * @param job job of new employee.
     * @param mgr manager's number of new employee.
     * @param deptno department number of new employee.
     * @param sal salary of new employee.
     * @param comm commitee of new employee.
     * @param hiredate hire date of new employee.
     * @return object containing information of added employee.
     * @throws EmployeeNotFoundException
     */
    public EmployeeInfo addNewEmployee(String ename, String job, Integer mgr,
                               Integer deptno, Float sal, Float comm, java.sql.Date hiredate)
                               throws EmployeeNotFoundException, DatabaseConnectException{

        return db.addNewEmployee( ename, job, mgr,
                                  deptno, sal, comm, hiredate);
    }

    /**Modify record in database.
     * @param empno number of employee.
     * @param ename name of employee.
     * @param job job of employee.
     * @param mgr manager's number of employee.
     * @param deptno department number of employee.
     * @param sal salary of employee.
     * @param comm commitee of employee.
     * @param hiredate hire date of employee.
     * @return object containing information of added employee.
     * @throws EmployeeNotFoundException
     */
    public EmployeeInfo modifyEmployee(Integer empno, String ename, String job, Integer mgr,
                               Integer deptno, Float sal, Float comm, java.sql.Date hiredate)
                               throws EmployeeNotFoundException, DatabaseConnectException{

        return db.modifyEmployee( empno, ename, job, mgr,
                                  deptno, sal, comm, hiredate);
    }
}